<div id="breadcrumb" class="clearfix mt_10">
    <ul class="h_list no_list_style ah">
        <li><a href="<?php echo site_url('admin/dashboard', true); ?>">Bảng điều khiển</a></li>
        <li class="SecondLast"><a href="<?php echo site_url('admin/cms/article/filtered_list/' . $return_url, true); ?>">Danh sách <?php echo $module_title; ?></a></li>
    </ul>
</div>
<div class="std_header auto_height">
    <div class="left">
        <strong>Quản lý danh sách <?php echo $module_title; ?></strong>
    </div>
    <div class="right">
        <button type="button" class="gray_btn" onclick="window.location='<?php echo site_url('admin/cms/article/edit', true); ?>'">
            <span>Thêm mới</span>
        </button>
    </div>
</div>
<div class="std_header search_header auto_height">
    <div class="std" align="center">
        <table cellpadding="0" cellspacing="5" border="0">
            <tr>
                <td>
                    <strong>Ngày tạo</strong>
                </td>
                <td>
                    <input name="filters[created_at_from]" placeholder="Từ ngày" type="text" class="std_input date_picker" value="<?php echo $filters['created_at_from']; ?>" />
                </td>
                <td style="pdl_10">
                    -
                </td>
                <td>
                    <input name="filters[created_at_to]" placeholder="Đến ngày" type="text" class="std_input date_picker" value="<?php echo $filters['created_at_to']; ?>" />
                </td>
                <td style="padding-left: 10px">
                    <strong>Ngày xuất bản</strong>
                </td>
                <td>
                    <input name="filters[publish_day_from]" placeholder="Từ ngày" type="text" class="std_input date_picker" value="<?php echo $filters['publish_day_from']; ?>" />
                </td>
                <td style="pdl_10">
                    -
                </td>
                <td>
                    <input name="filters[publish_day_to]" placeholder="Đến ngày" type="text" class="std_input date_picker" value="<?php echo $filters['publish_day_to']; ?>" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <strong>Chuyên mục</strong>
                    <select onchange="admin_cms_article.change_value(this.value, this.name); return admin_cms_article.act_filter();" placeholder="Tất cả" name="filters[ca.category_ids][value]">
                        <option value="-1">-- Tất cả --</option>
                        <?php foreach ($categories as $cat) :?>
                        <?php if (intval($cat->parent_id) > 0) :?>└--<?php endif; ?>
                        <option <?php if (isset($filters['ca.category_ids']['value']) && intval($filters['ca.category_ids']['value']) == intval($cat->id)) :?>selected="selected"<?php endif; ?> value="<?php echo get_field($cat, 'id'); ?>"><?php echo get_field($cat, 'name'); ?></option>
                        <?php endforeach; ?>
                    </select>
                </td>
                <td style="pdl_10" colspan="2">
                    <strong>Tác giả</strong>
                    <select onchange="admin_cms_article.change_value(this.value, this.name); return admin_cms_article.act_filter();" placeholder="Tất cả" name="filters[user_id][value]">
                        <option value="-1">-- Tất cả --</option>
                        <?php foreach ($users as $user) :?>
                        <option <?php if (isset($filters['user_id']['value']) && $filters['user_id']['value'] == get_field($user, 'id')) :?>selected="selected"<?php endif; ?> value="<?php echo get_field($user, 'id'); ?>">
                            <?php echo get_field($user, 'username'); ?>
                        </option>
                        <?php endforeach; ?>
                    </select>
                </td>
                <td style="padding-left: 10px" colspan="4">
                    <strong>Tiêu điểm</strong>
                    <select onchange="admin_cms_article.change_value(this.value, this.name); return admin_cms_article.act_filter();" placeholder="Tất cả" name="filters[hot_article][value]">
                        <option value="-1" <?php if (isset($filters['hot_article']['value']) && intval($filters['hot_article']['value']) == -1) :?>selected="selected"<?php endif; ?>>-- Tất cả --</option>
                        <option value="1" <?php if (isset($filters['hot_article']['value']) && intval($filters['hot_article']['value']) == 1) :?>selected="selected"<?php endif; ?>>Có</option>
                        <option value="0" <?php if (isset($filters['hot_article']['value']) && intval($filters['hot_article']['value']) == 0) :?>selected="selected"<?php endif; ?>>Không</option>
                    </select>
                    <strong>Kiểu tin</strong>
                    <select onchange="admin_cms_article.change_value(this.value, this.name); return admin_cms_article.act_filter();" placeholder="Tất cả" name="filters[type][value]">
                        <option value="-1">-- Tất cả --</option>
                        <?php foreach ($this->cms_article_model->get_list_types() as $type => $label) :?>
                        <option value="<?php echo $type; ?>" <?php if (isset($filters['type']['value']) && intval($filters['type']['value']) == intval($type)) :?>selected="selected"<?php endif; ?>><?php echo $label; ?></option>
                        <?php endforeach; ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="8">
                    <div class="bl">
                        <strong>Tin nổi bật trang chủ</strong>
                        <select onchange="admin_cms_article.change_value(this.value, this.name); return admin_cms_article.act_filter();" placeholder="Tất cả" name="filters[top_home][value]">
                            <option value="-1" <?php if (isset($filters['top_home']['value']) && intval($filters['top_home']['value']) == -1) :?>selected="selected"<?php endif; ?>>-- Tất cả --</option>
                            <option value="1" <?php if (isset($filters['top_home']['value']) && intval($filters['top_home']['value']) == 1) :?>selected="selected"<?php endif; ?>>Có</option>
                            <option value="0" <?php if (isset($filters['top_home']['value']) && intval($filters['top_home']['value']) == 0) :?>selected="selected"<?php endif; ?>>Không</option>
                        </select>
                        <input type="hidden" value="equal" name="filters[top_home][type]" />
                        <input type="hidden" value="-1" name="filters[top_home][exclude]" />
                        <strong>Tin nổi bật chuyên mục</strong>
                        <select onchange="admin_cms_article.change_value(this.value, this.name); return admin_cms_article.act_filter();" placeholder="Tất cả" name="filters[top_category][value]">
                            <option value="-1" <?php if (isset($filters['top_category']['value']) && intval($filters['top_category']['value']) == -1) :?>selected="selected"<?php endif; ?>>-- Tất cả --</option>
                            <option value="1" <?php if (isset($filters['top_category']['value']) && intval($filters['top_category']['value']) == 1) :?>selected="selected"<?php endif; ?>>Có</option>
                            <option value="0" <?php if (isset($filters['top_category']['value']) && intval($filters['top_category']['value']) == 0) :?>selected="selected"<?php endif; ?>>Không</option>
                        </select>
                        <input type="hidden" value="equal" name="filters[top_category][type]" />
                        <input type="hidden" value="-1" name="filters[top_category][exclude]" />
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div class="std clearfix mt_10" align="center">
        <?php global $alphas; ?>
        <?php $last_character = $alphas[count($alphas) - 1]; ?>
        <?php foreach ($alphas as $character) :?>
        <a <?php if (isset($filters['title']['value']) && $filters['title']['value'] == $character) :?>style="font-weight: bolder"<?php else :?>style="opacity: 0.6"<?php endif; ?> href="#" onclick="admin_cms_article.change_value('<?php echo $character; ?>', 'filters[title][value]'); admin_cms_article.act_filter(); return false;"><?php echo $character; ?></a>
        <?php if ($last_character != $character) :?> | <?php endif; ?>
        <?php endforeach; ?>
    </div>
    <div class="std clearfix mt_10" align="center">
        <button type="button" class="gray_btn" onclick="return admin_cms_article.act_filter()">
            <span>Tìm kiếm</span>
        </button>
        &nbsp;
        <button type="button" class="gray_btn" onclick="return admin_cms_article.reset_filters('frm_article_gridview')">
            <span>Xóa lọc</span>
        </button>
    </div>
</div>
<div id="article_management">
    <div class="mt_10">
        <?php $this->load->view('cms/article/message'); ?>
    </div>
    <div id="tab_list">
        <?php if (count($collection) != 0) : ?>
        <?php $paginator = $this->load->view('cms/article/paginator', null, true); echo $paginator; ?>
        <?php endif; ?>
        <input type="hidden" name="current_page" id="current_page" value="<?php echo $current_page; ?>" />
        <div class="block" id="lst_article">
            <table class="gridview" width="100%" cellpadding="0" cellspacing="0" border="0">
                <thead>
                <tr>
                    <td><input id="check_all" type="checkbox" onclick="btn_util.check_all(this.checked, '.chk_id')" /></td>
                    <td><b>ID</b></td>
                    <td colspan="2"><b>Tiêu đề</b></td>
                    <td width="100px"><b>Tác giả</b></td>
                    <td colspan="4"><b>Chuyên mục</b></td>
                </tr>
                </thead>
                <tbody>
                <tr class="filters">
                    <td colspan="2">
                        <input placeholder="ID" type="text" class="small_filter" name="filters[ca.id][value]" title="Tìm kiếm theo id bài viết" value="<?php echo $filters['ca.id']['value']; ?>" />
                        <input type="hidden" value="equal" name="filters[ca.id][type]" />
                    </td>
                    <td colspan="2">
                        <input placeholder="Từ khóa" type="text" class="wide_filter" name="filters[title][value]" title="Tìm kiếm theo tiêu đề bài viết" value="<?php echo $filters['title']['value']; ?>" />
                        <input type="hidden" value="text" name="filters[title][type]" />
                    </td>
                    <td>
                        <select onchange="return admin_cms_article.act_filter();" placeholder="Tất cả" name="filters[user_id][value]">
                            <option value="-1">-- Tất cả --</option>
                            <?php foreach ($users as $user) :?>
                            <option <?php if (isset($filters['user_id']['value']) && $filters['user_id']['value'] == get_field($user, 'id')) :?>selected="selected"<?php endif; ?> value="<?php echo get_field($user, 'id'); ?>">
                                <?php echo get_field($user, 'username'); ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                        <input type="hidden" value="equal" name="filters[user_id][type]" />
                        <input type="hidden" value="-1" name="filters[user_id][exclude]" />
                    </td>
                    <td>
                        <select onchange="return admin_cms_article.act_filter();" placeholder="Tất cả" name="filters[ca.category_ids][value]">
                            <option value="-1">-- Tất cả --</option>
                            <?php foreach ($categories as $cat) :?>
                            <?php if (intval($cat->parent_id) > 0) :?>└--<?php endif; ?>
                            <option <?php if (isset($filters['ca.category_ids']['value']) && intval($filters['ca.category_ids']['value']) == intval($cat->id)) :?>selected="selected"<?php endif; ?> value="<?php echo get_field($cat, 'id'); ?>"><?php echo get_field($cat, 'name'); ?></option>
                            <?php endforeach; ?>
                        </select>
                        <input type="hidden" value="in" name="filters[ca.category_ids][type]" />
                        <input type="hidden" value="-1" name="filters[ca.category_ids][exclude]" />
                    </td>
                    <td>
                        <select onchange="return admin_cms_article.act_filter();" placeholder="Tất cả" name="filters[hot_article][value]">
                            <option value="-1" <?php if (isset($filters['hot_article']['value']) && intval($filters['hot_article']['value']) == -1) :?>selected="selected"<?php endif; ?>>-- Tất cả --</option>
                            <option value="1" <?php if (isset($filters['hot_article']['value']) && intval($filters['hot_article']['value']) == 1) :?>selected="selected"<?php endif; ?>>Có</option>
                            <option value="0" <?php if (isset($filters['hot_article']['value']) && intval($filters['hot_article']['value']) == 0) :?>selected="selected"<?php endif; ?>>Không</option>
                        </select>
                        <input type="hidden" value="equal" name="filters[hot_article][type]" />
                        <input type="hidden" value="-1" name="filters[hot_article][exclude]" />
                    </td>
                    <td width="150px" colspan="2">
                        <button class="gray_btn" type="submit">
                            <span>Lọc</span>
                        </button>
                        <button class="gray_btn" type="button" onclick="return admin_cms_article.reset_filters('frm_article_gridview')">
                            <span>Xóa lọc</span>
                        </button>
                    </td>
                </tr>
                <?php if (count($collection) != 0) : ?>
                    <?php foreach ($collection as $article) : ?>
                    <tr <?php if ($article->status != 1) :?>class="deactive"<?php endif; ?>>
                        <input type="hidden" value="" class="edit_url"/>
                        <td width="30px" valign="top">
                            <input class="chk_id" type="checkbox" name="selected[]" value="<?php echo $article->id; ?>" />
                        </td>
                        <td width="30px" valign="top">
                            <?php echo $article->id; ?>
                        </td>
                        <td valign="top" width="100%" colspan="7">
                            <div class="bl">
                                <div class="frame" style="width: 100px; height: 80px; overflow: hidden;">
                                    <img width="100px" src="<?php echo render_src($article->image); ?>" />
                                </div>
                            </div>
                            <div class="bl ml_10" style="min-width: 500px">
                                <p><strong><a href="<?php echo site_url('admin/cms/article/edit/id/' . $article->id . '/return/' . $return_url, true); ?>"><?php echo get_field($article, 'title'); ?></a></strong></p>
                                <p class="small_datetime"><span class="icon icon_author"></span> Gửi bởi: <strong><?php echo get_field($article, 'author'); ?></strong> - Ngày gửi: <strong><?php echo render_date(get_field($article, 'created_at')); ?></strong> - Xuất bản: <strong><?php echo render_date(get_field($article, 'publish_day')); ?></strong></p>
                                <p class="small_datetime" style="width: 600px">
                                    <?php echo $article->description; ?>
                                </p>

                                <p class="mt_10">
                                    <strong><a title="Chỉnh sửa" class="icon icon_edit" href="<?php echo site_url('admin/cms/article/edit/id/' . $article->id . '/return/' . $return_url, true); ?>"></a></strong>
                                    <strong><a title="Xuất bản bài viết" onclick="return admin_cms_article.publish_article(<?php echo $article->id; ?>, 'frm_article_gridview', '<?php echo $return_url; ?>')" class="icon icon_publish" href="<?php echo site_url('admin/cms/article/publish_article/id/' . $article->id . '/return/' . $return_url, true); ?>"></a></strong>
                                    <strong><a title="Gỡ bỏ bài viết" onclick="return admin_cms_article.unpublish_article(<?php echo $article->id; ?>, 'frm_article_gridview', '<?php echo $return_url; ?>')" class="icon icon_unpublish" href="<?php echo site_url('admin/cms/article/unpublish/id/' . $article->id . '/return/' . $return_url, true); ?>"></a></strong>
                                </p>
                                <div class="bl">
                                    <div class="bl">
                                        <input id="chk_<?php echo $article->id; ?>_hot_article" onclick="return admin_cms_article.update_hot_article(this)" type="checkbox" value="<?php echo $article->id; ?>" <?php if (get_field($article, 'hot_article') == 1) :?>checked="checked"<?php endif; ?>/>
                                    </div>
                                    <div class="bl">
                                        <label for="chk_<?php echo $article->id; ?>_hot_article" style="line-height: 20px; margin-left: 2px">Tiêu điểm</label>
                                    </div>
                                </div>
                                <div class="bl ml_10">
                                    <div class="bl">
                                        <input id="chk_<?php echo $article->id; ?>_top_home" onclick="return admin_cms_article.update_top_home(this)" type="checkbox" value="<?php echo $article->id; ?>" <?php if (get_field($article, 'top_home') == 1) :?>checked="checked"<?php endif; ?>/>
                                    </div>
                                    <div class="bl">
                                        <label for="chk_<?php echo $article->id; ?>_top_home" style="line-height: 20px; margin-left: 2px">Nổi bật trang chủ</label>
                                    </div>
                                </div>
                                <div class="bl ml_10">
                                    <div class="bl">
                                        <input id="chk_<?php echo $article->id; ?>_top_category" onclick="return admin_cms_article.update_top_category(this)" type="checkbox" value="<?php echo $article->id; ?>" <?php if (get_field($article, 'top_category') == 1) :?>checked="checked"<?php endif; ?>/>
                                    </div>
                                    <div class="bl">
                                        <label for="chk_<?php echo $article->id; ?>_top_category" style="line-height: 20px; margin-left: 2px">Nổi bật mục</label>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                        <?php endforeach; ?>
                    <?php else : ?>
                <tr>
                    <td colspan="9" style="padding: 10px">
                        <p align="center">Danh sách <?php echo $module_title; ?> là rỗng trong thời điểm này hoặc truy vấn tìm kiếm không tìm thấy kết quả, <a href="<?php echo site_url('admin/cms/article/filtered_list/' . $return_url, true); ?>">Thử lại</a></p>
                    </td>
                </tr>
                    <?php endif; ?>
                </tbody>
                <tfoot>
                </tfoot>
            </table>
        </div>
        <?php if (isset($paginator) && count($collection) > 0) :?>
            <?php echo $paginator; ?>
        <?php endif; ?>
    </div>
</div>